#include "GlobalPrec.h"

bool GameScene::AddGameLayer(CSString classname)
{
	GameLayer* layer = GameLayerConfigMgr::Instance()->CreateLayer(classname);
	return AddGameLayer(classname,layer);
}

bool GameScene::AddGameLayer(CSString classname,CSString layername)
{
	GameLayer* layer = GameLayerConfigMgr::Instance()->CreateLayer(classname);
	return AddGameLayer(layername,layer);
}

bool GameScene::AddGameLayer(CSString layername,GameLayer* layer)
{
	mGameLayerMap.Insert(layername,layer);
	addChild(layer,layer->GetZOrder());
	return true;
}

void GameScene::MTAddGameLayer(CSString classname)
{
	GameLayerConfigMgr::Instance()->MTCreateLayer(classname,this);
}

void GameSceneMgr::Init(GameSceneRegister& regist)
{
	regist.Register(&mSceneMap);
}

void GameSceneMgr::RunScene(CSString name)
{
	ObjCreatorBase* base = mSceneMap.FindRef(name);
	if(!base)
		return ;
	GameScene* scene = (GameScene*)base->Create();
	if(!scene||!scene->init())
		return ;
	scene->autorelease();
	if(mNowScene)
	{
		CCDirector::sharedDirector()->replaceScene(scene);
		mNowScene=scene;
		scene->Init();
	}
	else
	{
		CCDirector::sharedDirector()->runWithScene(scene);
		mNowScene=scene;
		scene->Init();
	}
}

